package k.daniel.databindingdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import k.daniel.databindingdemo.bean.ObservableUserBean;
import k.daniel.databindingdemo.databinding.ActivitySimpleVariableBinding;

public class TwoWayDataBindingActivity extends AppCompatActivity {
    ObservableUserBean userBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivitySimpleVariableBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_simple_variable);
        String url="http://pic.58pic.com/58pic/15/01/62/79v58PIChzm_1024.jpg";
        userBean = new ObservableUserBean("daniel", "zhao", 25, true,url);
        binding.setUser(userBean);
        binding.setActivity(this);
        new Thread(new Runnable() {
            @Override
            public void run() {
                int count=0;
              while (true)
              {
                  count++;
                  userBean.setAge(userBean.getAge()+1);
//                  userBean.setFirstName(count+"");
                  System.out.println("age is changed.");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
            }
        }).start();
    }

    public void submit(View v){
        Toast.makeText(this,userBean.toString(),Toast.LENGTH_SHORT).show();
    }
}
